﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.OpenGL;
using Silvermoon.Windows;
using OutlookHub.Utils;

namespace OutlookHub.Controls
{
    public class ToggleSwitchControl : StackPanel
    {
        private Label label;
        private ToggleSwitch toggleSwitch;

        public ToggleSwitchControl()
            : base()
        {
            Orientation = StackPanelOrientation.Horizontal;
            FillControlIndex = 0;
            label = new Label { LineAlignment = Silvermoon.Controls.Alignment.Center, Margin = new Margin(0, 0, 168, 0), Font = FontPool.MediumRegularFont };
            toggleSwitch = new ToggleSwitch { Margin = new Margin(null, 5, 4, 5), Width = 120, On = "", Off = "" };
            toggleSwitch.CheckedChanged += new EventHandler(OnCheckedChanged);
            Controls.Add(label, toggleSwitch);
            OnCheckedChanged(null, null);
        }


        public bool IsChecked
        {
            get { return toggleSwitch.IsChecked; }
            set { toggleSwitch.IsChecked = value; }
        }

        private void OnCheckedChanged(object sender, EventArgs e)
        {
            label.Text = IsChecked ? "On" : "Off";
        }

        public event EventHandler CheckedChanged
        {
            add { toggleSwitch.CheckedChanged += value; }
            remove { toggleSwitch.CheckedChanged -= value; }
        }

    }
}
